﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Weazel.Gezel.Simulator.Reference.IpBlocks
{
	[IpBlockAttribute("pongcontroller")]
	public class Controller : AbstractIpBlock
	{
		private const int LeftCanWritePinNumber = 0;
		private const int LeftDoWritePinNumber = 1;
		private const int LeftPinNumber = 2;

		private const int RightCanWritePinNumber = 3;
		private const int RightDoWritePinNumber = 4;
		private const int RightPinNumber = 5;

		private const int IsFirstCanWritePinNumber = 6;
		private const int IsFirstDoWritePinNumber = 7;
		private const int IsFirstPinNumber = 8;


		public Controller(string name) : base(name)
		{
		}

		public override void SetParameter(string _name)
		{
		}

		public override void Run()
		{
			try
			{
			}
			catch (Exception e)
			{
				String message = e.GetType().ToString() + " " +
					e.Message + " trace: \n" + e.StackTrace;

				System.Windows.Forms.MessageBox.Show(message);
			}
		}

		public override bool CheckTerminal(int n, string tname, IoDirection dir)
		{
			switch (n)
			{
				case LeftCanWritePinNumber:
					return (dir == AbstractIpBlock.IoDirection.Input && tname == "ctrl_left_can_write");
				case LeftDoWritePinNumber:
					return (dir == AbstractIpBlock.IoDirection.Output && tname == "ctrl_left_do_write");
				case LeftPinNumber:
					return (dir == AbstractIpBlock.IoDirection.Output && tname == "ctrl_left");

				case RightCanWritePinNumber:
					return (dir == AbstractIpBlock.IoDirection.Input && tname == "ctrl_right_can_write");
				case RightDoWritePinNumber:
					return (dir == AbstractIpBlock.IoDirection.Output && tname == "ctrl_right_do_write");
				case RightPinNumber:
					return (dir == AbstractIpBlock.IoDirection.Output && tname == "ctrl_right");

				case IsFirstCanWritePinNumber:
					return (dir == AbstractIpBlock.IoDirection.Input && tname == "ctrl_is_first_can_write");
				case IsFirstDoWritePinNumber:
					return (dir == AbstractIpBlock.IoDirection.Output && tname == "ctrl_is_first_right_do_write");
				case IsFirstPinNumber:
					return (dir == AbstractIpBlock.IoDirection.Output && tname == "ctrl_is_first");

				default:
					throw new NotSupportedException("Controller: CheckTerminal() unknown 'n' value");
			}
		}

	}
}
